<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="服装类别名称" class="myform-item">
          <el-input v-model="form.title" placeholder="请输入服装类别名称" clearable @keyup.enter.native="onSearch"></el-input>
        </el-form-item>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onEdit()" icon="el-icon-plus">新建</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column label="服装类别名称" align="center" prop="base_category">
      </el-table-column>
      <el-table-column label="尺码" align="center" prop="base_size_code">
        <template slot-scope="{ row }">
          <span v-for="(item, index) in row.base_size_code" :key="index">
            {{ item.size_code.title }}
            <span v-if="item.height_code.length!=0">({{ item.height_code.title }}/{{
              item.waist_code.title
            }})</span>{{ row.base_size_code.length - 1 != index ? "，" : "" }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="基码" align="center" prop="brand">
        <template slot-scope="{ row }">
          <span>
            {{ row.base_code.size_code.title }}
            <span v-if="row.base_code.height_code.length!=0">
              ({{
                row.base_code.height_code.title
              }}/{{ row.base_code.waist_code.title }})
            </span>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="base_status">
        <template slot-scope="{ row }">
          <div :style="{ color: row.base_status == 1 ? '#67C23A' : '#F56C6C' }">
            {{ row.base_status == 1 ? "启用" : "禁用" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right">
        <template slot-scope="{ row }">
          <el-button type="text" @click="onEdit(row.id)">编辑</el-button>
          <el-button type="text" style="color: red" v-if="row.base_status == 1" @click="onIs(row.id, 0)">禁用</el-button>
          <el-button type="text" style="color: #67c23a" v-if="row.base_status == 0"
            @click="onIs(row.id, 1)">启用</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :form="form" :total="total" @paginationPostOrderTaskList="postAdminOperateGetBasecode" />
  </div>
</template>

<script>
import {
  postAdminOperateGetBasecode,
  postAdminOperateDisableBasecode,
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      dialogVisible: false, //审核
      form: {
        title: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;
    this.postAdminOperateGetBasecode(form);
  },
  methods: {
    // 查看
    onEdit(id) {
      if (!id) {
        this.$router.push({
          name: "ProcessMaintenanceCodons",
        });
      } else {
        this.$router.push({
          name: "ProcessMaintenanceCodons",
          query: { id },
        });
      }
    },
    async onIs(id, status) {
      let obj = {
        id: id,
        is_disable: status,
      };
      this.$confirm(`确定${status == 0 ? "禁用" : "启用"}`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          await postAdminOperateDisableBasecode(obj);
          let form = this.form;
          this.postAdminOperateGetBasecode(form);
        })
        .catch(() => { });
    },
    // 删除
    onDelete(id) {
      let obj = {
        id,
      };
      let { form } = this;
      this.$confirm("确定删除该标签种类?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminOperateDelOrtherProduct(obj).then((res) => {
            this.postAdminOperateGetBasecode(form);
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 采购列表
    async postAdminOperateGetBasecode(data) {
      this.loading = true;
      this.form = data;
      postAdminOperateGetBasecode(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminOperateGetBasecode(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;

  >div {
    display: flex;
  }

  &-item {
    margin-right: 10px;
  }
}

.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
